{% extends "projects/project_edit_base.html" %}

{% load i18n %}

{% block title %}{% trans "Edit Notifications" %}{% endblock %}

{% block nav-dashboard %} class="active"{% endblock %}

{% block editing-option-edit-proj %}class="active"{% endblock %}

{% block project-notifications-active %}active{% endblock %}
{% block project_edit_content_header %}{% trans "Notifications" %}{% endblock %}

{% block project_edit_content %}
  <p class="help_text">
    {% trans "Configure Notifications to be sent on build failures." %}
  </p>

  {% if emails or urls %}
    <h3>{% trans "Existing Notifications" %}</h3>
    <p>
      {% if emails %}
      <ul>
        <h2> Emails </h2>
        {% for email in emails %}
            <li>
            {{ email }}
            </li>
        {% endfor %}
      </ul>
      {% endif %}

      {% if urls %}
      <ul>
        <h2> Webhooks </h2>
        {% for url in urls %}
            <li>
            {{ url }}
            </li>
        {% endfor %}
      </ul>
      {% endif %}

    <h3>{% trans "Remove Notifications" %}</h3>
      <p>
          <form method="post" action="{% url "projects_notification_delete" project.slug %}">
              {% csrf_token %}
            <select id="id_email" name="email">
            {% for email in emails %}
              <option value="{{ email.email }}">{{ email }}</option>
            {% endfor %}
            {% for url in urls %}
              <option value="{{ url.url }}">{{ url }}</option>
            {% endfor %}
            </select>
            <input type="submit" value="{% trans "Remove" %}">
          </form>
      </p>
  {% endif %}


  <h3>{% trans "New Email Notifications" %}</h3>
  <p>
    {% trans "Add an email address to notify" %}
  </p>
  <form method="post" action=".">{% csrf_token %}
    {{ email_form }}
    <p>
      <input style="display: inline;" type="submit" value="{% trans "Add" %}">
    </p>
  </form>

  <h3>{% trans "New Webhook Notifications" %}</h3>
  <p>
    {% trans "Add a URL to notify" %}
  </p>
  <form method="post" action=".">{% csrf_token %}
    {{ webhook_form }}
    <p>
      <input style="display: inline;" type="submit" value="{% trans "Add" %}">
    </p>
  </form>
{% endblock %}
